<div class="data-action" id="dataAction" style="padding:5px;">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td colspan="5" style='padding-bottom:10px;'>
                <label>选择店铺：</label>
                <{input type='object' name='shop_id' cols="name" object="shop" app="ome"}>
                <label style='padding-left:10px;'>统计时间类型：</label>
                <select class='x-input-select inputstyle' name='time_type'>
                    <option value='pay_time'>按结算时间</option>
                    <option value='biz_time'>按业务时间</option>
                </select>
                <label style='padding-left:10px;'>结算状态：</label>
                <select class='x-input-select inputstyle' name='status'>
                    <option value='0'>未开始</option>
                    <option value='1'>成功</option>
                    <option value='2'>失败</option>
                </select>
                <label style='padding-left:10px;'>选择科目：</label>
                <{input type='object' name='fee_item_id' object="bill_fee_item" app='finance'}>
            </td>
        </tr>
        <tr colspan="5">
            <td>
                <label>时间范围：</label>
                <{input type="date" vtype="date" name="time_from" style="width:66px; font-family:arial;" value=$time_from}>
                <span style='padding:0px 5px'>至</span>
                <{input type="date" vtype="date" name="time_to" style="width:66px; font-family:arial;" value=$time_to}>
                <{button class="filterBtn btn-thirdly" label='确定' style='padding-left:10px;'}>

                <{button class="dataBtn btn-fourthly" time_from=$yesterday time_to=$yesterday label="昨日"}>
                <{button class="dataBtn btn-fourthly" time_from=$today time_to=$today label="今日"}>
                <{button class="dataBtn btn-fourthly" time_from=$this_week_from time_to=$this_week_to label="本周"}>
                <{button class="dataBtn btn-fourthly" time_from=$last_week_from time_to=$last_week_to label="上周"}>
            </td>
        </tr>
        <tr>
            <td><img style="position:relative;top:11px;" src="<{$env.app.res_url}>/trade.png">&nbsp;<span>销售收支款:<{$feedata['trade']|cur}></span></td>
            <td><img style="position:relative;top:11px;" src="<{$env.app.res_url}>/plat.png">&nbsp;平台费用:<{$feedata['plat']|cur}></td>
            <td><img style="position:relative;top:11px;" src="<{$env.app.res_url}>/branch.png">&nbsp;仓储费用:<{$feedata['branch']|cur}></td>
            <td><img style="position:relative;top:11px;" src="<{$env.app.res_url}>/delivery.png">&nbsp;物流费用:<{$feedata['delivery']|cur}></td>
            <td><img style="position:relative;top:11px;" src="<{$env.app.res_url}>/other.png">&nbsp;其他费用:<{$feedata['other']|cur}></td>
        </tr>
    </table>
</div>
<script>
(function(){
//if($E('.num')) $E('.num').innerHTML+=' 数据非及时显示，当天数据请于第二天查看';
var _finder = finderGroup['<{$name}>'],
dataAction= $('dataAction'),
data_ipt=$$(dataAction.getElements('input[name^=time_]'),dataAction.getElements('select')),
from=dataAction.getElement('input[name=time_from]'),
to=dataAction.getElement('input[name=time_to]');

if(_finder&&_finder.form){
    fdoc = document.createDocumentFragment();
    data_ipt.each(function(ipt){
        fdoc.appendChild(new Element('input[type=hidden]', {'name': ipt.name, value: ipt.value}));
    });
    _finder.form.appendChild(fdoc);
}

data_ipt.addEvent('change',function(e){
    if(_finder&&_finder.form){
        var ipt=$E('input[name='+this.name+']',_finder.form);
        if(ipt)ipt.value=this.value;
    }
});

<{if $report == "month"}>
var today=new Date();
$$('select.date_select').each(function(item){
/* $A(item.options).each(function(opt,i){
if(opt.text==today.getFullYear() || opt.text==today.getMonth()+1) opt.selected=true;
}); */
item.addEvent('change',function(){
    setDate(this.get('id').split('_')[0]);
});
});

setDate();

function setDate(){
    var arguments=arguments.length===0 ? ['from','to'] : arguments;
    $A(arguments).each(function(item){
        dataAction.getElement('input[name=time_'+item+']').value=$(item+'_year').options[$(item+'_year').selectedIndex].text+'-'+$(item+'_month').options[$(item+'_month').selectedIndex].text+'-01';
    });
}
<{/if}>

$$('.select-tabs a').addEvent('click',function(e){
    e.stop();
    W.page(this.href,{data:'report='+this.type,method:"post"});
});

function setChartData(flag,e){
    if(!check_data(from,to))return;
    var params=dataAction.toQueryString(),
    itemcur=$E('.chart-view .chart-item-cur');
    dataAction.store('_data',params);
    if(flag&&itemcur&&$E('iframe',itemcur)) $E('iframe',itemcur).src+='&'+params;
    if(flag) url='index.php?app=<{$env.get.app}>&ctl=<{$env.get.ctl}>&act=<{$env.get.act}>';
    else url=e.target.href||e.target.getParent().href;
    W.page(url, {data:params, method:'post',onComplete:function(){
        if(_finder) _finder.filter.value=params;
    }});
}
if($('select_shop')) $('select_shop').addEvent('change',function(e){setChartData(true);});
dataAction.getElement('.filterBtn').addEvent('click',function(e){setChartData(true);});

var packet=$('finder-packet-<{$name}>');
if(packet) packet.addEvent("click",function(e){
    if(e.target.tagName.toLowerCase()=="a" || e.target.getParent().tagName.toLowerCase()=="a"){
        e.stop();
        setChartData(false,e);
    }
});

    <{if $report == "month"}>
    function check_data(from,to){
        if(Date.parse(to.value.replace(/-/gi,"/"))<Date.parse(from.value.replace(/-/gi,"/"))){
            return MessageBox.error('选择开始时间必须早于结束时间');
        }
        return true;
    }
    <{else}>
    function check_data(from,to){
        var data=[],
        _return=[from,to].every(function(el){
            if(!/^(19|20)[0-9]{2}-([1-9]|0[1-9]|1[012])-([1-9]|0[1-9]|[12][0-9]|3[01])+$/.test(el.value)){
                new MessageBox('请录入日期格式yyyy-mm-dd',{type:'error',autohide:true});
                el.focus();
                return false;
            }
            data.push(Date.parse(el.value.replace(/-/gi,"/")));
            return true;
        });

        if(!_return)return null;
        if(data[1]<data[0]){
            return MessageBox.error('选择开始时间必须早于结束时间');
        }
        return _return;
    }
    <{/if}>

    var dataBtn=dataAction.getElements('.dataBtn');
    dataBtn.each(function(el,i){
        if(el.get('time_from')==from.value && el.get('time_to')==to.value)
            el.addClass('btn-fourthly-cur');
        el.addEvent('click',function(e){
            from.value=this.get('time_from');
            to.value=this.get('time_to');

        dataAction.getElement('.filterBtn').fireEvent('click');
    });
    });

    if($ES('.large .span-auto').length)
        $ES('.large .span-auto').each(function(el){
            el.store('tip:title',el.get('title')).store('tip:text',el.get('info'));
            Xtip.attach(el);
        });
})();

</script>
